
#ifndef __PENDINA_H__
#define __PENDINA_H__

#include <google/protobuf/message.h>

#include "thinclient.h"
#include "PluginManager.h"

#define IMAGE_WIDTH     480
#define IMAGE_HEIGHT    320

#define XP_API_NEW				new
#define XP_API_DEL(a)			{ if(a) { delete (a); a=NULL; } }

template <typename S>
class CSingleton 
{
public:
	CSingleton() {}
	virtual ~CSingleton()
	{
		XP_API_DEL(m_instance);
	}

	static void release()
	{
		XP_API_DEL(m_instance);
	}

	static S *getInstance()
	{
		if(!m_instance)
		{
			m_instance = XP_API_NEW S();
		}

		return m_instance;
	}

	// Support for classes with parameters in constructors
	template <class P1>
	static S *getInstance(const P1 &val1)
	{
		if(!m_instance)
		{
			m_instance = XP_API_NEW S(val1);
		}

		return m_instance;
	}

	template <class P1, class P2>
	static S *getInstance(const P1 &val1, const P2 &val2)
	{
		if(!m_instance)
		{
			m_instance = XP_API_NEW S(val1, val2);
		}
		return m_instance;
	}

	
private:
	static S *m_instance;
};

template <class S> S *CSingleton<S>::m_instance = NULL;

class LocalClass : public CSingleton <LocalClass>
{
	friend class CSingleton <LocalClass>;
	Plugin* renderer;
	bool mInitialized;

	LocalClass(void) : mInitialized(false) { }
    ~LocalClass(void) { }

public:
	void LoadAssets() { }
	void Initialize(int,int);
	void Render();

	//
	void Update(float) { }
	
	void ProcessInputs(float, bool Keys[]) { }


	bool IsInitialized() const { return mInitialized; }
};

#define Pendina()	LocalClass::getInstance()

#endif
